class Encoder
{
	public static inline var encoding =
	"0123456789ABCDEF";
	public static inline var maxlinelength = 32;
	
	public static function encode(str : String) : String
	{
		// this performs an input validation in two ways:
		// 1. Max string length is forced by truncation.
		// 2. SQL injection is avoided by using a hex encoding scheme.
		//    This adds some overhead but guarantees that SQL cannot
		//    be attacked in this way.
		str = str.substr(0,maxlinelength);
		return StringTools.baseEncode(str, encoding);
	}

	public static function unencode(str : String) : String
	{
		return StringTools.baseDecode(str, encoding);
	}
}
